/**
 * 
 */
package br.com.portal.fitness.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.PostConstruct;

import org.primefaces.model.LazyDataModel;
import org.primefaces.model.SortMeta;
import org.primefaces.model.SortOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import br.com.portal.fitness.dao.IUsuarioDAO;
import br.com.portal.fitness.model.Usuario;



/**
 * @author rodolfo.julio
 *
 */

@Controller(value="usuarioMb")
public class UsuarioController {
	
	
	@Autowired
	private IUsuarioDAO dao;
	
	
	private LazyDataModel<Usuario> lista;
	
	
	@PostConstruct
	public void init(){
		lista = new LazyDataModel<Usuario>() {
			
			/**
			 * 
			 */
			private static final long serialVersionUID = 1L;

			@Override
			public List<Usuario> load(int first, int pageSize,
					List<SortMeta> multiSortMeta, Map<String, String> filters) {
				SortMeta m = null;
				if (multiSortMeta != null && !multiSortMeta.isEmpty()){
					m = multiSortMeta.get(0);
				}
				return dao.buscaPorPaginacao(first, pageSize, (m != null ? m.getSortField() : null), SortOrder.ASCENDING.toString(), filters);
			}
			
		};
		
	}
	
	public UsuarioController() {
	
	}
		
	
	public void setDao(IUsuarioDAO dao) {
		this.dao = dao;
	}

	public LazyDataModel<Usuario> getLista() {
		return lista;
	}

	public void setLista(LazyDataModel<Usuario> lista) {
		this.lista = lista;
	}
	
	
	

	
	
}
